package main

import (
	"OldPackageTest/go_mysql/sqlx/config"
	"OldPackageTest/go_mysql/sqlx/model"
	"fmt"
)

func insertRow() {
	sqlStr := "insert into student(name,age) values(?, ?)"
	res, err := config.DB.Exec(sqlStr, "超哥牛逼", 1)
	if err != nil {
		return
	}
	affected, _ := res.RowsAffected()
	fmt.Println(affected, "insert success...")
}

// 批量插入
func bathInsertRow() {
	user := []model.User{
		{Name: "111", Age: 11},
		{Name: "222", Age: 22},
		{Name: "333", Age: 33},
		{Name: "444", Age: 44},
	}
	sqlStr := "insert into student(name,age) values(:name, :age)"
	_, err := config.DB.NamedExec(sqlStr, user)
	if err != nil {
		fmt.Println("bath insert failed, err:%v", err)
		return
	}

}
